perm filename PINIT3.2[EAL,HE] blob
sn#676512 filedate 1982-09-27 generic text, type C, neo UTF8
COMMENT ⊗ VALID 00004 PAGES
C REC PAGE DESCRIPTION
C00001 00001
C00002 00002 {$NOMAIN Parser initialization (part of it) }
C00023 00003 { Externally defined routines from elsewhere: }
C00024 00004 (* routine to make predeclared identifiers & constants: initIdents *)
C00037 ENDMK
C⊗;
{$NOMAIN Parser initialization (part of it) }
const
(* Constants from EDIT; need these for the constants section *)
maxLines = 28; (* smaller on the 11 than on the 10 *)
maxPPLines = 18;
maxBpts = 25;
maxTBpts = 20; (* max could be exceeded by huge case stmnt *)
listinglength = 2000; (* Length of Listingarray *)
(* Random type declarations for OMSI/SAIL compatibility *)
type
byte = 0..255; (* doesn't really belong here, but... *)
ascii = char;
atext = text;
{ Define all the pointer types here }
strngp = ↑strng;
statementp = ↑statement;
varidefp = ↑varidef;
nodep = ↑node;
identp = ↑ident;
tokenp = ↑token;
reswordp = ↑resword;
(* This one is used whenever a pointer is needed for which the definition
is missing from this file; naturally, all pointers use the same space *)
dump = ↑integer;
cursorp = array[1..4] of integer;
(* datatype definitions *)
datatypes = (pconstype, varitype, svaltype, vectype, rottype, transtype,
frametype, eventtype, strngtype, labeltype, proctype, arraytype,
reftype, valtype, cmontype, nulltype, undeftype,
dimensiontype, mactype, macargtype, freevartype);
scalar = real;
cstring = packed array [1..10] of ascii;
c4str = packed array [1..4] of ascii;
c5str = packed array [1..5] of ascii;
c20str = packed array [1..20] of ascii;
linestr = packed array [1..130] of ascii;
strng = record
next: strngp;
ch: cstring;
end;
(* statement definitions *)
stmntypes = (progtype, blocktype, coblocktype, endtype, coendtype,
fortype, iftype, whiletype, untiltype, casetype,
calltype, returntype,
printtype, prompttype, pausetype, aborttype, assigntype,
signaltype, waittype, enabletype, disabletype, cmtype,
affixtype, unfixtype,
movetype, operatetype, opentype, closetype, centertype,
stoptype, retrytype,
requiretype, definetype, macrotype, commenttype, dimdeftype,
setbasetype, wristtype, tovaltype, declaretype, emptytype);
(* more??? *)
statement = packed record
next, last: statementp; (* ↑ to lexical tokens? *)
stlab: varidefp;
exprs: nodep; (* any expressions used by this statement *)
nlines: integer;
bpt: boolean;
case stype: stmntypes of
progtype: (pcode: statementp; errors: integer);
blocktype,
declaretype,
endtype,
coendtype: (bcode, bparent: statementp; blkid: identp;
level, numvars: 0..255; variables: varidefp);
coblocktype: (threads: nodep; nthreads: integer; cblkid: identp);
fortype: (forvar, initial, step, final: nodep; fbody: statementp);
whiletype,
untiltype: (cond: nodep; body: statementp);
casetype: (index: nodep; range, ncases: integer; caselist: nodep);
iftype: (icond: nodep; thn, els: statementp);
pausetype: (ptime: nodep);
prompttype,
printtype,
aborttype: (plist: nodep; debugLev: integer);
returntype: (retval, rproc: nodep);
calltype,
assigntype: (what, aval: nodep);
affixtype,
unfixtype: (frame1, frame2, byvar, atexp: nodep; rigid: boolean);
signaltype,
waittype: (event: nodep);
movetype,
operatetype,
opentype,
closetype,
centertype,
stoptype: (cf, clauses: nodep);
retrytype: (rcode, rparent: statementp; olevel: integer);
cmtype: (oncond: nodep; conclusion: statementp;
deferCm, exprCm: boolean; cdef: varidefp);
enabletype,
disabletype: (cmonlab: varidefp);
requiretype: (rfil: boolean; rfils: strngp; rfilen: integer);
definetype: (macname,mpars: varidefp; macdef: tokenp);
commenttype: (len: integer; str: strngp; cbody: statementp);
dimdeftype: (dimname: varidefp; dimexpr: nodep);
setbasetype,
wristtype: (fvec, tvec: nodep);
tovaltype: (vstr: strngp; vlen: integer; waitp: boolean);
end;
(* auxiliary definitions: variable, etc. *)
varidef = packed record
next,dnext: varidefp;
name: identp;
level: 0..255; (* environment level *)
offset: 0..255; (* environment offset *)
dtype: varidefp; (* to hold the dimension info *)
tbits: 0..15; (* special type bits: array = 1, proc = 2, ref = 4 & ? *)
dbits: 0..15; (* for use by debugger/interpreter *)
case vtype: datatypes of
arraytype: (a: nodep);
proctype: (p: nodep);
labeltype,
cmontype: (s: statementp);
mactype: (mdef: statementp);
macargtype: (marg: tokenp);
pconstype: (c: nodep);
dimensiontype: (dim: nodep);
end;
(* definition of the ubiquitous NODE record *)
nodetypes = (exprnode, leafnode, listnode, clistnode, colistnode, forvalnode,
deprnode, viaptnode, apprnode, destnode, durnode,
sfacnode, wobblenode, swtnode, nullingnode, wristnode, cwnode,
arrivalnode, departingnode,
ffnode, forcenode, stiffnode, gathernode, cmonnode, errornode,
calcnode, arraydefnode, bnddefnode, bndvalnode,
waitlistnode, procdefnode, tlistnode, dimnode, commentnode);
exprtypes = ( svalop, (* scalar operators *)
sltop, sleop, seqop, sgeop, sgtop, sneop, (* relations *)
notop, orop, xorop, andop, eqvop, (* logical *)
saddop, ssubop, smulop, sdivop, snegop, sabsop, (* scalar ops *)
sexpop, maxop, minop, intop, idivop, modop,
sqrtop, logop, expop, timeop, (* functions *)
sinop, cosop, tanop, asinop, acosop, atan2op, (* trig *)
vdotop, vmagnop, tmagnop,
vecop, (* vector operators *)
vmakeop, unitvop, vaddop, vsubop, crossvop, vnegop,
svmulop, vsmulop, vsdivop, tvmulop, wrtop,
tposop, taxisop,
transop, (* trans operators *)
tmakeop, torientop, ttmulop, tvaddop, tvsubop, tinvrtop,
vsaxwrop, constrop, ftofop, deproachop, fmakeop, vmkfrcop,
ioop, (* i/o operators *)
queryop, inscalarop,
specop, (* special operators *)
arefop, callop, grinchop, macroop, vmop, adcop, dacop,
badop,
addop, subop, negop, mulop, divop, absop); (* for parsing *)
leaftypes = pconstype..strngtype;
reltypes = sltop..sgtop;
forcetypes = (force,absforce,torque,abstorque,angvelocity);
node = record
next: nodep;
case ntype: nodetypes of
leafnode: (case ltype: leaftypes of
varitype: (vari: varidefp; vid: identp);
pconstype: (cname: varidefp; pcval: nodep);
svaltype: (s: scalar; wid: integer);
vectype: (v: dump);
transtype: (t: dump);
strngtype: (length: integer; str: strngp) ); (* also used by commentnodes *)
dimnode: (time, distance, angle, dforce: integer);
end;
(* records for parser: ident, token, resword *)
ident = record
next: identp;
length: integer;
name: strngp;
predefined: varidefp;
end;
tokentypes = (reswdtype, identtype, constype, comnttype, delimtype, labeldeftype,
macpartype);
constypes = svaltype..strngtype;
reswdtypes = (stmnttype, filtype, clsetype, decltype, optype, edittype);
filtypes = (abouttype,alongtype,attype,bytype,defertype,dotype,elsetype,
errmodestype,fromtype,handtype,intype,nonrigidlytype,rigidlytype,
sourcefiletype,steptype,thentype,totype,untltype,viatype,
withtype,worldtype,zeroedtype,oftype,wheretype,nowaittype,
ontype,offtype,ppsizetype,collecttype,alltype,lextype);
clsetypes = (approachtype,arrivaltype,departuretype,departingtype,durationtype,
errortype,forcetype,forceframetype,forcewristtype,gathertype,
nildeproachtype,nonullingtype,nullingtype,stiffnesstype,
torquetype,velocitytype,wobbletype,
cwtype,ccwtype,stopwaittimetype,angularvelocitytype,
fxtype,fytype,fztype,mxtype,mytype,mztype,
t1type,t2type,t3type,t4type,t5type,t6type,tbltype);
edittypes = (getcmd,savecmd,insertcmd,renamecmd,startcmd,gocmd,proceedcmd,
stepcmd,sstepcmd,nstepcmd,gstepcmd,executecmd,setcmd,tracecmd,
breakcmd,unbreakcmd,tbreakcmd,definecmd,markcmd,unmarkcmd,
popcmd);
token = record
next: tokenp;
case ttype: tokentypes of
constype: (cons: nodep);
comnttype: (len: integer; str: strngp);
delimtype: (ch: ascii);
reswdtype: (case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes) );
identtype: (id: identp);
labeldeftype: (lab: varidefp);
macpartype: (mpar: varidefp);
end;
resword = record
next: reswordp;
length: integer;
name: strngp;
case rtype: reswdtypes of
stmnttype: (stmnt: stmntypes);
filtype: (filler: filtypes);
clsetype: (clause: clsetypes);
decltype: (decl: datatypes);
optype: (op: exprtypes);
edittype: (ed: edittypes);
end;
(* Print related stuff - not much here *)
listingarray = packed array [0..listinglength] of ascii;
(* Global variables *)
var
(* From ALMAIN *)
b:boolean;
ch:ascii;
ltime: real;
(* From PARSE *)
reswords: array [0..26] of reswordp;
idents: array [0..26] of identp;
macrostack: array [1..10] of tokenp;
curmacstack: array [1..10] of varidefp;
macrodepth: integer;
curchar, maxchar, curline: integer;
curBlock,newDeclarations: statementp;
curProc: varidefp;
pnode: nodep;
nodim, distancedim, timedim, angledim,
forcedim, torquedim, veldim, angveldim: varidefp;
fvstiffdim, mvstiffdim: nodep;
filedepth: integer;
curpage: integer;
sysVars,unVars: varidefp;
errcount: integer;
outerBlock: statementp;
curVariable: varidefp;
curMotion: statementp;
endOk,coendOk: integer;
moveLevel: integer;
curErrhandler, curCmon: statementp;
endOfLine, backup, expandmacros, flushcomments, dimCheck: boolean;
semiseen, shownline: boolean;
eofError: boolean;
inMove,inCoblock: boolean;
curtoken: token;
file1,file2,file3,file4,file5: atext;
line: linestr;
(* From INTERP *)
(* curInt, activeInts, readQueue, allPdbs: pdbp;
curEnv, sysEnv: envheaderp;
clkQueue: nodep;
allEvents: dump;
STLevel: integer;
etime: integer;
curtime: integer;
stime: integer;
msg: messagep;
inputp: integer;
debugLevel: integer; *)
d1: array[1..15] of dump;
tSingleThreadMode: boolean;
resched, running, escapeI, singleThreadMode: boolean;
msgp: boolean; (* flag set if any messages pending *)
inputReady: boolean;
inputLine: array [1..20] of ascii;
(* From EDIT *)
lines: array [1..maxLines] of dump;
ppLines: array [1..maxPPLines] of dump;
marks: array [1..20] of integer;
cursorStack: array [1..15] of cursorp;
bpts: array [1..maxBpts] of statementp;
tbpts: array [1..maxTBpts] of statementp;
debugPdbs: array [0..10] of dump;
screenheight,dispHeight: integer;
ppBufp,oppBufp,ppOffset,ppSize,nmarks: integer;
lbufp,cursor,ocur,cursorLine,fieldnum,lineNum,findLine,pcLine: integer;
firstDline,topDline,botDline,firstLine,lastLine: integer;
freeLines,oldLines: dump;
findStmnt: statementp;
nbpts,ntbpts: integer;
eCurInt: dump;
dProg: statementp;
smartTerminal: boolean;
setUp,setExpr,setCursor,dontPrint,outFilep,newVarOk,collect: boolean;
eBackup: boolean;
eSingleThreadMode: boolean;
listing: packed array [0..listinglength] of ascii;
lbuf: array [1..160] of ascii;
ppBuf: array [1..100] of ascii;
outFile: atext;
eCurToken: token;
(* Various device & variable pointers *)
speedfactor: dump;
barm: dump;
(* Various constant pointers *)
xhat,yhat,zhat,nilvect: dump;
niltrans: dump;
bpark, ypark, gpark, rpark: dump; (* arm park positions *)
{ Externally defined routines from elsewhere: }
(* From ALLOC *)
function newNode: nodep; external;
function newToken: tokenp; external;
function newIdent: identp; external;
function newStrng: strngp; external;
function newVaridef: varidefp; external;
(* From PAUX1 *)
function hash(ch: ascii): integer; external;
(* routine to make predeclared identifiers & constants: initIdents *)
procedure init2Idents; external;
procedure init2Idents;
var id: identp; n: nodep; str: strngp;
sfId,degId,secId: identp; t,tp: tokenp; (* for macro defs *)
function makeIdent(s: cstring): identp;
var id: identp; str: strngp; i: integer;
begin
id := newIdent;
with id↑ do
begin
predefined := nil;
str := newStrng;
str↑.ch := s;
name := str;
length := 10;
while s[length] = ' ' do length := length - 1;
end;
i := hash(id↑.name↑.ch[1]); (* find proper bucket *)
id↑.next := idents[i]; (* link us onto list of identifiers *)
idents[i] := id;
makeIdent := id;
end;
function ConMake(s: cstring; d: datatypes; vdim: varidefp;
sv: real; n: nodep): identp;
var id: identp; vdef: varidefp;
begin
id := makeIdent(s);
vdef := newVaridef;
id↑.predefined := vdef;
if n = nil then (* need to make up a new constant node *)
begin
n := newNode;
with n↑ do
begin
next := nil;
ntype := leafnode;
ltype := d;
if d = svaltype then s := sv;
end;
end;
with vdef↑ do
begin
name := id;
vtype := pconstype;
dtype := vdim;
offset := 0;
tbits := 0;
dbits := 0;
c := n;
dnext := nil;
end;
ConMake := id;
end;
function MacMake(s: cstring): identp;
var id: identp; vdef: varidefp;
begin
id := makeIdent(s);
vdef := newVaridef;
id↑.predefined := vdef;
vdef↑.name := id;
vdef↑.vtype := macargtype;
MacMake := id;
end;
function CToken(num: real; tp: tokenp): tokenp;
var t: tokenp; n: nodep;
begin
t := newToken;
if tp <> nil then tp↑.next := t;
n := newNode;
t↑.ttype := constype;
t↑.cons := n;
n↑.ntype := leafnode;
n↑.ltype := svaltype;
n↑.s := num;
CToken := t;
end;
function IToken(i: identp; tp: tokenp): tokenp;
var t: tokenp;
begin
t := newToken;
if tp <> nil then tp↑.next := t;
t↑.ttype := identtype;
t↑.id := i;
IToken := t;
end;
function RToken(r: reswdtypes): tokenp;
var t: tokenp;
begin
t := newToken;
t↑.ttype := reswdtype;
t↑.rtype := r;
RToken := t;
end;
function WithToken(tp: tokenp): tokenp;
var t: tokenp;
begin
t := RToken(filtype);
if tp <> nil then tp↑.next := t;
t↑.filler := withtype;
WithToken := t;
end;
function OpToken(tp: tokenp): tokenp;
var t: tokenp;
begin
t := RToken(optype);
if tp <> nil then tp↑.next := t;
t↑.op := seqop;
OpToken := t;
end;
function ClToken(cl: clsetypes; tp: tokenp): tokenp;
var t: tokenp;
begin
t := RToken(clsetype);
if tp <> nil then tp↑.next := t;
t↑.clause := cl;
ClToken := t;
end;
function FilToken(fil: filtypes; tp: tokenp): tokenp;
var t: tokenp;
begin
t := RToken(filtype);
if tp <> nil then tp↑.next := t;
t↑.filler := fil;
FilToken := t;
end;
procedure SpdSt(id: identp; spd: real);
var t,tp: tokenp;
begin
t := IToken(sfId,nil);
id↑.predefined↑.marg := t;
tp := RToken(stmnttype);
t↑.next := tp;
tp↑.stmnt := assigntype;
t := CToken(spd,tp);
t↑.next := nil;
end;
procedure SpdCl(id: identp; spd: real);
var t,tp: tokenp;
begin
t := WithToken(nil);
id↑.predefined↑.marg := t;
tp := IToken(sfId,t);
t := OpToken(tp);
tp := CToken(spd,t);
tp↑.next := nil;
end;
procedure SwtCl(id: identp; swt: real);
var t,tp: tokenp;
begin
t := WithToken(nil);
id↑.predefined↑.marg := t;
tp := ClToken(stopwaittimetype,t);
t := OpToken(tp);
tp := CToken(swt,t);
tp↑.next := nil;
end;
begin (* now make up the constants *)
id := ConMake('BPARK ',transtype,distancedim,0.0,nil);
id↑.predefined↑.c↑.t := bpark;
id := ConMake('YPARK ',transtype,distancedim,0.0,nil);
id↑.predefined↑.c↑.t := ypark;
id := ConMake('RPARK ',transtype,distancedim,0.0,nil);
id↑.predefined↑.c↑.t := rpark;
id := ConMake('GPARK ',transtype,distancedim,0.0,nil);
id↑.predefined↑.c↑.t := gpark;
id := ConMake('NILTRANS ',transtype,distancedim,0.0,nil);
n := id↑.predefined↑.c;
n↑.t := niltrans;
id := ConMake('NILROT ',transtype,angledim,0.0,n);
id := ConMake('STATION ',transtype,distancedim,0.0,n);
id := ConMake('XHAT ',vectype,nodim,0.0,nil);
id↑.predefined↑.c↑.v := xhat;
id := ConMake('YHAT ',vectype,nodim,0.0,nil);
id↑.predefined↑.c↑.v := yhat;
id := ConMake('ZHAT ',vectype,nodim,0.0,nil);
id↑.predefined↑.c↑.v := zhat;
id := ConMake('NILVECT ',vectype,nodim,0.0,nil);
id↑.predefined↑.c↑.v := nilvect;
id := ConMake('TRUE ',svaltype,nodim,1.0,nil);
n := id↑.predefined↑.c;
degId := ConMake('DEG ',svaltype,angledim,0.0,n);
id := ConMake('DEGREES ',svaltype,angledim,0.0,n);
id := ConMake('INCH ',svaltype,distancedim,0.0,n);
id := ConMake('INCHES ',svaltype,distancedim,0.0,n);
id := ConMake('OUNCES ',svaltype,forcedim,0.0,n);
id := ConMake('OZ ',svaltype,forcedim,0.0,n);
secId := ConMake('SEC ',svaltype,timedim,0.0,n);
id := ConMake('SECOND ',svaltype,timedim,0.0,n);
id := ConMake('SECONDS ',svaltype,timedim,0.0,n);
id := ConMake('FALSE ',svaltype,nodim,0.0,nil);
id := ConMake('CM ',svaltype,distancedim,0.3937008,nil);
id := ConMake('GM ',svaltype,forcedim,0.035274,nil);
id := ConMake('RADIANS ',svaltype,angledim,57.295779,nil);
id := ConMake('PI ',svaltype,nodim,3.1415927,nil);
id := ConMake('LBS ',svaltype,forcedim,16.0,nil);
id := ConMake('RPM ',svaltype,angveldim,6.0,nil);
id := ConMake('CRLF ',strngtype,nodim,0.0,nil);
str := newStrng;
str↑.ch[1] := chr(15B); (* cr *)
str↑.ch[2] := chr(12B); (* lf *)
id↑.predefined↑.c↑.str := str;
id↑.predefined↑.c↑.length := 2;
id := ConMake('PANIC_BUTT',svaltype,nodim,1024.0,nil); (* '2000 *)
id↑.name↑.next := newStrng;
id↑.name↑.next↑.ch := 'ON ';
id↑.length := 12;
id := ConMake('EXCESSIVE_',svaltype,nodim,2048.0,nil); (* '4000 *)
id↑.name↑.next := newStrng;
id↑.name↑.next↑.ch := 'FORCE ';
id↑.length := 15;
id := ConMake('TIME_OUT ',svaltype,nodim,4096.0,nil); (* '10000 *)
id := MacMake('DIRECTLY '); (* now make predeclared macros *)
t := WithToken(nil); (* "WITH APPROACH = NILDEPROACH" *)
id↑.predefined↑.marg := t;
tp := ClToken(approachtype,t);
t := OpToken(tp);
tp := ClToken(nildeproachtype,t);
t := WithToken(tp); (* "WITH DEPARTURE = NILDEPROACH" *)
tp := ClToken(departuretype,t);
t := OpToken(tp);
tp := ClToken(nildeproachtype,t);
tp↑.next := nil;
SpdSt(MacMake('QUICK '),1.0); (* QUICK = "SPEEDFACTOR := 1.0" *)
SpdSt(MacMake('SLOW '),3.0); (* SLOW = "SPEEDFACTOR := 3.0" *)
SpdSt(MacMake('CAUTIOUS '),4.0); (* CAUTIOUS = "SPEEDFACTOR := 4.0" *)
SpdCl(MacMake('QUICKLY '),1.0); (* QUICKLY = "WITH SPEEDFACTOR = 1.0" *)
SpdCl(MacMake('NORMALLY '),2.0); (* NORMALLY = "WITH SPEEDFACTOR = 2.0" *)
SpdCl(MacMake('SLOWLY '),3.0); (* SLOWLY = "WITH SPEEDFACTOR = 3.0" *)
SpdCl(MacMake('CAUTIOUSLY'),4.0); (* CAUTIOUSLY = "WITH SPEEDFACTOR = 4.0" *)
id := MacMake('APPROXIMAT');
id↑.name↑.next := newStrng;
id↑.name↑.next↑.ch := 'ELY ';
id↑.length := 13;
t := WithToken(nil); (* APPROXIMATELY = "WITH NONULLING" *)
id↑.predefined↑.marg := t;
tp := ClToken(nonullingtype,t);
tp↑.next := nil;
id := MacMake('PRECISELY ');
t := WithToken(nil); (* PRECISELY = "WITH NULLING" *)
id↑.predefined↑.marg := t;
tp := ClToken(nullingtype,t);
tp↑.next := nil;
SwtCl(MacMake('GENTLY '),0.0); (* GENTLY = "WITH STOPWAITTIME = 0.0" *)
SwtCl(MacMake('TIGHTLY '),0.5); (* TIGHTLY = "WITH STOPWAITTIME = 0.5" *)
id := MacMake('TIL ');
t := filToken(steptype,nil); (* TIL = "STEP 1 UNTIL" *)
id↑.predefined↑.marg := t;
tp := CToken(1.0,t);
t := filToken(untltype,tp);
t↑.next := nil;
end;